package com.jml.jdk8.BinaryOpera;


import java.util.Comparator;
import java.util.function.BinaryOperator;

/**
 * @author:jml
 * @date: 2019/7/30 0030 22:39
 * @description：
 */
public class BinaryOperaTest<T> {

    public static void main(String[] args) {
        BinaryOperaTest<Integer> binaryOperaTest = new BinaryOperaTest<>();
        Integer computer = binaryOperaTest.computer(1, 3, (a, b) -> a + b);
        System.out.println(computer);
        System.out.println("------------------------------------------------------");

        //打印小的
        String aShort = binaryOperaTest.getShort("123", "12345", (a, b) -> a.length() - b.length());
        System.out.println(aShort);


    }


    public T computer(T a,T b, BinaryOperator<T> binaryOperator){
        return binaryOperator.apply(a,b);
    }

    //两个静态方法
    public String getShort(String a,String b,Comparator<String> comparator){
        return BinaryOperator.minBy(comparator).apply(a,b);
    }

    public String getLong(String a,String b,Comparator<String> comparator){
        return BinaryOperator.maxBy(comparator).apply(a,b);
    }
}
